# -*- coding:utf-8 -*-
import serial
import time
import minimalmodbus


def md_write(com_port,baudrate,addr,reg,num):
    try:
        axis1=minimalmodbus.Instrument(com_port,addr) 
        axis1.serial.baudrate=baudrate 
        axis1.serial.timeout=0.8
        axis1.write_register(reg,num)
    except IOError:
        return 'IOError'
    except WindowsError:
        return 'WinError'
    except :
        return 'Error'
    return 'sucessful'

def md_read(com_port,baudrate,addr,reg):
    try:
        axis1=minimalmodbus.Instrument(com_port,addr) 
        axis1.serial.baudrate=baudrate 
        axis1.serial.timeout=0.8
        r=axis1.read_register(reg)
    except IOError:
        return 'IOError'
    except WindowsError:
        return 'WinError'
    except :
        return 'Error'
    return r